﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SQT.tracnghiem.BaiViet
{
    public partial class NewsSearch : System.Web.UI.Page
    {
        public string keyword,fap;
        public int page;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                keyword = Request.QueryString["keyword"];
                fap = keyword;
                page = int.Parse(Request.QueryString["page"]);
                keyword = convertToUnSign(keyword);
            }
            catch
            {
                Response.Redirect("~/trang-chu");
            }
        }
        public static string convertToUnSign(string s)
        {
            string convert = "ĂÂÀẰẦÁẮẤẢẲẨÃẴẪẠẶẬỄẼỂẺÉÊÈỀẾẸỆÔÒỒƠỜÓỐỚỎỔỞÕỖỠỌỘỢƯÚÙỨỪỦỬŨỮỤỰÌÍỈĨỊỲÝỶỸỴĐăâàằầáắấảẳẩãẵẫạặậễẽểẻéêèềếẹệôòồơờóốớỏổởõỗỡọộợưúùứừủửũữụựìíỉĩịỳýỷỹỵđ\".:;'<>?~!@#$%^&*()_+-=\\/*,";
            string To = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuiiiiiyyyyydaaaaaaaaaaaaaaaaaeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuiiiiiyyyyyd                           ";
            for (int i = 0; i < To.Length; i++)
            {
                s = s.Replace(convert[i], To[i]);
            }
            return s;
        }
        public static string convertToUrl(string s)
        {
            string url = "";
            s = s.ToLower();
            if (s.IndexOf(' ') != -1)
            {
                string[] split = new string[s.Split(' ').Length];
                split = s.Split(' ');

                for (int i = 0; i < split.Length; i++)
                {
                    url += convertToUnSign(split[i].Trim());
                    if (i < split.Length - 1)
                        url += "-";
                }
                s = url;
            }
            else
            {
                url += convertToUnSign(s);
            }
            s = url;
            return s;
        }
        public static string limitTitle(string s)
        {
            string[] split = new string[s.Split(' ').Length];
            split = s.Split(' ');
            string title = "";
            if (split.Length > 15)
            {
                for (int i = 0; i < 15; i++)
                {
                    title += split[i];
                    title += " ";
                }
                s = title.Trim();
            }
            return s;
        }
    }
}